package com.sikao.app.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.sikao.app.R;
import com.sikao.app.adapter.BuyerOrderExtraInfoAdapter;
import com.sikao.app.adapter.PicturesAdapter;
import com.sikao.app.bean.Bean;
import com.sikao.app.bean.BuyerOrderDetailBean;
import com.sikao.app.bean.BuyerOrderOperateSubmitBean;
import com.sikao.app.bean.GetOrderDetailSubmitBean;
import com.sikao.app.bean.UserInfoBean;
import com.sikao.app.dao.BasicInfModel;
import com.sikao.app.dao.BuyerOrderDetailModel;
import com.sikao.app.dao.BuyerOrderOperateModel;
import com.sikao.app.myinterface.Callback;
import com.sikao.app.net.HttpApi;
import com.sikao.app.net.OnNetBackListener;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.ConstantClass;
import com.sikao.app.utils.JSONUtil;
import com.sikao.app.utils.SizeConvertUtils;
import com.sikao.app.utils.TimeUtil;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class BuyerOrderDetailActivity extends BaseActivity implements View.OnClickListener {

	private TextView titleTv;
	private TextView scheduleTv;
	private ImageView backIv;

	private TextView tvOrderNumber;
	private TextView tvStatus;
	private TextView tvName;
	private TextView tvPhone;
	private TextView tvCompanyName;
	private Button btnSendMail;
	private TextView tvGoodsType;
	private TextView tvGoodsName;
	private TextView tvQuantity;
	private TextView tvPrice;
	private TextView tvAllPrice;
	private TextView tvReleaseType;
	private TextView tvPayType;
	private TextView tvQuantityUnit;
	private TextView tvPriceUnit;
	private TextView tvPayMode;
	private TextView tvStartDate;
	private LinearLayout llWarehouseReceipt;
	private GridView gridViewWarehouseReceipt;
	private TextView tvDeliveryMode;
	private TextView tvDeliveryPlace;
	private GridView gridViewExtraInf;
	private LinearLayout llInspectionReport;
	private GridView gridViewInspectionReport;
	private LinearLayout llAcceptanceReport;
	private TextView tvGoodsWeight;
	private TextView tvCarriagePrice;
	private TextView tvFinalTotalPrice;
	private GridView gridViewAcceptanceReport;
	private Button btnCancelOrder;
	private Button btnApplyArbitration;
	private Button btnWaitArbitration;
	private Button btnViewArbitration;
	private Button btnFirstMoney;
	private Button btnSecondMoney;
	private Button btnSubmitReport;
	private Button btnHasSubmittedReport;
	private Button btnAgainSubmitReport;
	private Button btnConfirmInvoice;
	private Button btnThreeMoney;
	private Button btnEvaluate;
	private Button btnViewEvaluation;

	private int schedule;//订单进度 1、等待卖家确认订单，2、付首款，3、等待对方进行备货，4、等待对方付尾款，5.等待对方提交验收报告，6、等待对方验收发票，7、等待对方付尾款，8、等待对方评价，9、已完成
	private int status;//1、确认订单，2、等待对方付首款，3、进行备货，4、等待对方付尾款，5.等待对方提交验收报告，6、对方已提交验收报告，7、拒绝了验收报告，8、等待对方验收发票，9、等待对方付尾款，10、等待对方评价，11、已完成 12、取消了订单 13、申请了仲裁（仲裁中） 14、平台仲裁结束

	private BuyerOrderDetailModel buyerOrderDetailModel;
	private GetOrderDetailSubmitBean getOrderDetailSubmitBean;
	private PicturesAdapter warehouseReceiptAdapter, inspectionReportAdapter, acceptanceReportAdapter;
	private BuyerOrderExtraInfoAdapter buyerOrderExtraInfoAdapter;
	private List<String> warehouseReceiptList, inspectionReportList, acceptanceReportList;
	private String beanId;
	private BuyerOrderOperateModel buyerOrderOperateModel;
	private BuyerOrderOperateSubmitBean buyerOrderOperateSubmitBean = new BuyerOrderOperateSubmitBean();
	private BuyerOrderDetailBean bean;
	private Intent intent;

	private BasicInfModel basicInfModel;
	private int step;
	private DecimalFormat format = new DecimalFormat("0.00");

	public static final int ARBITRATE = 1;//仲裁
	public static final int SUBMIT_REPORT = 2;//提交验收报告
	public static final int EVALUATE = 3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_buyer_order_detail);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		beanId = getIntent().getStringExtra("bean");
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		scheduleTv = (TextView) findViewById(R.id.title_right_tv);
		tvOrderNumber = (TextView) findViewById(R.id.tv_order_number);
		tvStatus = (TextView) findViewById(R.id.tv_status);
		tvName = (TextView) findViewById(R.id.tv_name);
		tvPhone = (TextView) findViewById(R.id.tv_phone);
		tvCompanyName = (TextView) findViewById(R.id.tv_company_name);
		btnSendMail = (Button) findViewById(R.id.btn_send_mail);
		tvGoodsType = (TextView) findViewById(R.id.tv_goods_type);
		tvGoodsName = (TextView) findViewById(R.id.tv_goods_name);
		tvQuantity = (TextView) findViewById(R.id.tv_quantity);
		tvPrice = (TextView) findViewById(R.id.tv_price);
		tvAllPrice = (TextView) findViewById(R.id.tv_all_price);
		tvReleaseType = (TextView) findViewById(R.id.tv_release_type);
		tvPayType = (TextView) findViewById(R.id.tv_pay_type);
		llWarehouseReceipt = (LinearLayout) findViewById(R.id.ll_warehouse_receipt);
		gridViewWarehouseReceipt = (GridView) findViewById(R.id.gridView_warehouse_receipt);
		tvQuantityUnit = (TextView) findViewById(R.id.tv_quantity_unit);
		tvPriceUnit = (TextView) findViewById(R.id.tv_price_unit);
		tvPayMode = (TextView) findViewById(R.id.tv_pay_mode);
		tvStartDate = (TextView) findViewById(R.id.tv_start_date);
		tvDeliveryMode = (TextView) findViewById(R.id.tv_delivery_mode);
		tvDeliveryPlace = (TextView) findViewById(R.id.tv_delivery_place);
		gridViewExtraInf = (GridView) findViewById(R.id.gridView_extra_inf);
		llInspectionReport = (LinearLayout) findViewById(R.id.ll_inspection_report);
		gridViewInspectionReport = (GridView) findViewById(R.id.gridView_inspection_report);
		llAcceptanceReport = (LinearLayout) findViewById(R.id.ll_acceptance_report);
		tvGoodsWeight = (TextView) findViewById(R.id.tv_goods_weight);
		tvCarriagePrice = (TextView) findViewById(R.id.tv_carriage_price);
		tvFinalTotalPrice = (TextView) findViewById(R.id.tv_final_total_price);
		gridViewAcceptanceReport = (GridView) findViewById(R.id.gridView_acceptance_report);
		btnCancelOrder = (Button) findViewById(R.id.btn_cancel_order);
		btnApplyArbitration = (Button) findViewById(R.id.btn_apply_arbitration);
		btnWaitArbitration = (Button) findViewById(R.id.btn_wait_arbitration);
		btnViewArbitration = (Button) findViewById(R.id.btn_view_arbitration);
		btnFirstMoney = (Button) findViewById(R.id.btn_first_money);
		btnSecondMoney = (Button) findViewById(R.id.btn_second_money);
		btnSubmitReport = (Button) findViewById(R.id.btn_submit_report);
		btnHasSubmittedReport = (Button) findViewById(R.id.btn_has_submitted_report);
		btnAgainSubmitReport = (Button) findViewById(R.id.btn_again_submit_report);
		btnConfirmInvoice = (Button) findViewById(R.id.btn_confirm_invoice);
		btnThreeMoney = (Button) findViewById(R.id.btn_three_money);
		btnEvaluate = (Button) findViewById(R.id.btn_evaluate);
		btnViewEvaluation = (Button) findViewById(R.id.btn_view_evaluation);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		scheduleTv.setOnClickListener(this);
		btnSendMail.setOnClickListener(this);
		btnCancelOrder.setOnClickListener(this);
		btnApplyArbitration.setOnClickListener(this);
		btnViewArbitration.setOnClickListener(this);
		btnFirstMoney.setOnClickListener(this);
		btnSecondMoney.setOnClickListener(this);
		btnSubmitReport.setOnClickListener(this);
		btnAgainSubmitReport.setOnClickListener(this);
		btnConfirmInvoice.setOnClickListener(this);
		btnThreeMoney.setOnClickListener(this);
		btnEvaluate.setOnClickListener(this);
		btnViewEvaluation.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("订单详情");
		backIv.setVisibility(View.VISIBLE);
		scheduleTv.setText("进度");
		scheduleTv.setVisibility(View.VISIBLE);
		intent = new Intent();
		getOrderDetail(true);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				setResult(RESULT_OK, getIntent());
				finish();
				break;
			case R.id.btn_send_mail:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, SendMailActivity.class);
				intent.putExtra("type", "name");
				intent.putExtra("value", bean.getRes().getShop_info().getNickname());
				startActivity(intent);
				break;
			case R.id.btn_cancel_order:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						orderOperate("cancel");
					}
				});
				break;
			case R.id.btn_apply_arbitration:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, ArbitrateActivity.class);
				intent.putExtra("type", "buyer");
				intent.putExtra("bean", bean.getRes().getId());
				startActivityForResult(intent, ARBITRATE);
				break;
			case R.id.btn_view_arbitration:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, ArbitrationResultActivity.class);
				intent.putExtra("bean", bean.getRes().getId());
				intent.putExtra("type", "buyer");
				startActivity(intent);
				break;
			case R.id.btn_first_money:
				if (bean.getRes().getPay_type().equals("onLinePay")) {
					step = 1;
					getMyBalance();
				} else {
					payMoney(1);
				}
				break;
			case R.id.btn_second_money:
				if (bean.getRes().getPay_type().equals("onLinePay")) {
					step = 2;
					getMyBalance();
				} else {
					payMoney(2);
				}
				break;
			case R.id.btn_submit_report:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, SubmitAcceptanceReportActivity.class);
				intent.putExtra("bean", bean.getRes().getId());
				intent.putExtra("unit", bean.getRes().getGoods_info().getUnit());
				startActivityForResult(intent, SUBMIT_REPORT);
				break;
			case R.id.btn_again_submit_report:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, SubmitAcceptanceReportActivity.class);
				intent.putExtra("bean", bean.getRes().getId());
				intent.putExtra("unit", bean.getRes().getGoods_info().getUnit());
				startActivityForResult(intent, SUBMIT_REPORT);
				break;
			case R.id.btn_confirm_invoice:
				showDialog(new Callback() {
					@Override
					public void notice(int position) {
						buyerOrderOperateSubmitBean = new BuyerOrderOperateSubmitBean();
						orderOperate("receive");
					}
				});
				break;
			case R.id.btn_three_money:
				if (bean.getRes().getPay_type().equals("onLinePay")) {
					step = 3;
					getMyBalance();
				} else {
					payMoney(3);
				}
				break;
			case R.id.btn_evaluate:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, EvaluateActivity.class);
				intent.putExtra("bean", bean.getRes().getId());
				startActivityForResult(intent, EVALUATE);
				break;
			case R.id.btn_view_evaluation:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, EvaluationActivity.class);
				intent.putExtra("bean", bean.getRes().getId());
				intent.putExtra("type", "buyer");
				startActivity(intent);
				break;
			case R.id.title_right_tv:
				if (bean == null) {
					return;
				}
				intent.setClass(BuyerOrderDetailActivity.this, BuyerOrderScheduleActivity.class);
				if (bean.getRes().getStatus().equals("7") && bean.getRes().getIs_comment().equals("1")) {
					intent.putExtra("schedule", 8);
				} else {
					intent.putExtra("schedule", Integer.parseInt(bean.getRes().getStatus()));
				}
				startActivity(intent);
				break;
			default:
				break;
		}
	}

	@Override
	public void onBackPressed() {
		setResult(RESULT_OK, getIntent());
		super.onBackPressed();
	}

	/**
	 * 付款
	 */

	private void payMoney(final int step) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		View view;
		TextView tvAvailableMoney;
		if (bean.getRes().getPay_type().equals("onLinePay")) {
			view = View.inflate(this, R.layout.order_pay_money_dialog, null);//线上付款
			tvAvailableMoney = (TextView) view.findViewById(R.id.tv_available_money);
			tvAvailableMoney.setText(""+ConstantClass.balanceValue);
		} else {
			view = View.inflate(this, R.layout.buyer_order_offline_payment_dialog, null);//线下付款
		}
		builder.setView(view);
		final Dialog dialog = builder.create();
		TextView tvPayMoney = (TextView) view.findViewById(R.id.tv_pay_money);
		tvPayMoney.setText(bean.getRes().getThis_pay().getPayMoney());
		LinearLayout llPoundage = (LinearLayout) view.findViewById(R.id.ll_poundage);
		TextView tvPoundage = (TextView) view.findViewById(R.id.tv_poundage);
		final EditText etPayPassword = (EditText) view.findViewById(R.id.et_pay_password);
		Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);
		Button btnConfirm = (Button) view.findViewById(R.id.btn_confirm);
		if (step == 1) {
			llPoundage.setVisibility(View.VISIBLE);
			tvPoundage.setText(bean.getRes().getBuy_factorage());
		}
		btnCancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		btnConfirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (etPayPassword.getText().toString().length() == 0) {
					Toast.makeText(BuyerOrderDetailActivity.this, "请输入支付密码", Toast.LENGTH_SHORT).show();
					return;
				}
				buyerOrderOperateSubmitBean = new BuyerOrderOperateSubmitBean();
				buyerOrderOperateSubmitBean.setPayPassword(etPayPassword.getText().toString());
				if (step == 1) {
					buyerOrderOperateSubmitBean.setBuyerFactorage(bean.getRes().getBuy_factorage());
					//format
					buyerOrderOperateSubmitBean.setPayMoney(bean.getRes().getThis_pay().getPayMoney());
					orderOperate("payOne");
				}
				if (step == 2) {
					buyerOrderOperateSubmitBean.setPayMoney(bean.getRes().getThis_pay().getPayMoney());
					orderOperate("payTwo");
				}
				if (step == 3) {
					buyerOrderOperateSubmitBean.setPayMoney(bean.getRes().getThis_pay().getPayMoney());
					orderOperate("payThree");
				}
				dialog.dismiss();
			}
		});
		dialog.show();
		dialog.setCanceledOnTouchOutside(false);
		dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		Window dialogWindow = dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = SizeConvertUtils.dip2px(260);
		dialogWindow.setAttributes(lp);
		dialog.setCanceledOnTouchOutside(false);
	}

	private void getMyBalance() {

			basicInfModel = new BasicInfModel(this, new OnNetBackListener<UserInfoBean>() {
				@Override
				public void netBack(UserInfoBean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")) {
						if (data.getRes().getCash() != null) {
							ConstantClass.balanceValue = Float.valueOf(data.getRes().getCash());
						}
						if (data.getRes().getFrozen() != null) {
							ConstantClass.frozenFund = Float.valueOf(data.getRes().getFrozen());
						}
						if (data.getRes().getCredit() != null) {
							ConstantClass.creditValue = Float.valueOf(data.getRes().getCredit());
						}
						if (step == 1) {
							payMoney(1);
						}
						if (step == 2) {
							payMoney(2);
						}
						if (step == 3) {
							payMoney(3);
						}
					} else {
						Toast.makeText(BuyerOrderDetailActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});

		basicInfModel.request("{}", true);
	}

	/**
	 * 获取订单详情
	 *
	 * @param isShow 是否显示加载动画
	 */
	private void getOrderDetail(boolean isShow) {
		if (buyerOrderDetailModel == null) {
			buyerOrderDetailModel = new BuyerOrderDetailModel(this, new OnNetBackListener<BuyerOrderDetailBean>() {
				@Override
				public void netBack(BuyerOrderDetailBean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")) {
						bean = data;
						showContent();
					} else {
						Toast.makeText(BuyerOrderDetailActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
		}
		getOrderDetailSubmitBean = new GetOrderDetailSubmitBean();
		getOrderDetailSubmitBean.setOrderId(beanId);
		buyerOrderDetailModel.request(JSONUtil.toJSON(getOrderDetailSubmitBean), isShow);

	}

	private void showContent() {
		tvOrderNumber.setText(bean.getRes().getId());
		tvName.setText(bean.getRes().getShop_info().getNickname());
		tvPhone.setText(bean.getRes().getShop_info().getMobile());
		tvCompanyName.setText(bean.getRes().getShop_info().getCom_name());
		tvGoodsType.setText(bean.getRes().getGoods_info().getCat_name());
		tvGoodsName.setText(bean.getRes().getGoods_info().getTitle());
		tvQuantity.setText(bean.getRes().getNumber());
		tvQuantityUnit.setText(bean.getRes().getGoods_info().getUnit());
		tvPrice.setText(bean.getRes().getPrice());
		tvPriceUnit.setText(bean.getRes().getGoods_info().getUnit());
		tvAllPrice.setText(bean.getRes().getTotal_price());
		tvReleaseType.setText(bean.getRes().getGoods_info().getPublish_type_str());
		tvPayType.setText(bean.getRes().getGoods_info().getPay_method_str());
		tvPayMode.setText(bean.getRes().getGoods_info().getPay_type_str());
		if (bean.getRes().getGoods_info().getPublish_type().equals("1")) {
			llWarehouseReceipt.setVisibility(View.VISIBLE);
			warehouseReceiptList = new ArrayList<>();
			List<BuyerOrderDetailBean.ResBean.GoodsInfoBean.StorePicInfoBean> picBeans = bean.getRes().getGoods_info().getStore_pic_info();
			for (int i = 0; picBeans != null && i < picBeans.size(); i++) {
				warehouseReceiptList.add(HttpApi.BANNERUTL + picBeans.get(i).getUrl());
			}
			warehouseReceiptAdapter = new PicturesAdapter(this, warehouseReceiptList);
			gridViewWarehouseReceipt.setAdapter(warehouseReceiptAdapter);
		}
		tvStartDate.setText(TimeUtil.timeStampToTime(bean.getRes().getAdd_time(), "yyyy-MM-dd"));
		tvDeliveryMode.setText(bean.getRes().getGoods_info().getDelivery_type_str());
		tvDeliveryPlace.setText(bean.getRes().getGoods_info().getDelivery_area());
		/*if (bean.getRes().getOriginal_data() != null && bean.getRes().getOriginal_data().getAttr() != null) {
			buyerOrderExtraInfoAdapter = new BuyerOrderExtraInfoAdapter(this, bean.getRes().getOriginal_data().getAttr());
			gridViewExtraInf.setAdapter(buyerOrderExtraInfoAdapter);//附加信息

		}*/

		List<BuyerOrderDetailBean.ResBean.GoodsInfoBean.CheckReportInfoBean> reportList = bean.getRes().getGoods_info().getCheck_report_info();
		if (reportList != null && reportList.size() != 0) {
			inspectionReportList = new ArrayList<>();
			for (int i = 0; i < reportList.size(); i++) {
				inspectionReportList.add(HttpApi.BANNERUTL + reportList.get(i).getUrl());
			}
			inspectionReportAdapter = new PicturesAdapter(this, inspectionReportList);
			gridViewInspectionReport.setAdapter(inspectionReportAdapter);
		}
		dismissAllBtn();
		//验收提货状态 0默认初始值 1买家已提交 2卖家同意 3卖家不同意
		if (bean.getRes().getCheck_report_status() != null && !bean.getRes().getCheck_report_status().equals("0")) {
			llAcceptanceReport.setVisibility(View.VISIBLE);
			tvGoodsWeight.setText(bean.getRes().getCheck_report().getFinal_number());
			tvCarriagePrice.setText(bean.getRes().getCheck_report().getFreight());
			tvFinalTotalPrice.setText(bean.getRes().getCheck_report().getFinal_price());
			if (bean.getRes().getCheck_report().getFile_paths() != null) {
				acceptanceReportList = new ArrayList<>();
				for (int i = 0; i < bean.getRes().getCheck_report().getFile_paths().size(); i++) {
					acceptanceReportList.add(HttpApi.BANNERUTL + bean.getRes().getCheck_report().getFile_paths().get(i));
				}
				acceptanceReportAdapter = new PicturesAdapter(this, acceptanceReportList);
				gridViewAcceptanceReport.setAdapter(acceptanceReportAdapter);
			}
		}

		if (!bean.getRes().getException_status().equals("0")) {
			//取消
			if (bean.getRes().getException_status().equals("1")) {
				tvStatus.setText("订单已取消");
			}
			//过期
			if (bean.getRes().getException_status().equals("2")) {
				tvStatus.setText("订单已过期");
			}
			//冻结
			if (bean.getRes().getException_status().equals("3")) {
				tvStatus.setText("订单冻结中");
			}
			//仲裁中
			if (bean.getRes().getException_status().equals("4") && bean.getRes().getIs_end().equals("0")) {
				btnWaitArbitration.setVisibility(View.VISIBLE);
			}
			//仲裁后
			if (bean.getRes().getException_status().equals("4") && bean.getRes().getIs_end().equals("1")) {
				btnViewArbitration.setVisibility(View.VISIBLE);
			}
		} else {
			switch (bean.getRes().getStatus()) {
				case "0":
					btnCancelOrder.setVisibility(View.VISIBLE);
					tvStatus.setText("等待商家确认订单");
					break;
				case "1":
					btnCancelOrder.setVisibility(View.VISIBLE);
					tvStatus.setText("付首款");
					btnFirstMoney.setVisibility(View.VISIBLE);
					break;
				case "2":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("等待商家备货");
					break;
				case "3":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("付中期款");
					btnSecondMoney.setVisibility(View.VISIBLE);
					break;
				case "4":
					//验收提货状态 0默认初始值 1买家已提交 2卖家同意 3卖家不同意
					btnApplyArbitration.setVisibility(View.VISIBLE);
					if (bean.getRes().getCheck_report_status().equals("0")) {
						tvStatus.setText("提交验收报告");
						btnSubmitReport.setVisibility(View.VISIBLE);
					}
					if (bean.getRes().getCheck_report_status().equals("1")) {
						tvStatus.setText("已提交验收报告,等待商家确认");
						btnHasSubmittedReport.setVisibility(View.VISIBLE);
					}
					if (bean.getRes().getCheck_report_status().equals("2")) {
						tvStatus.setText("商家已接受验收报告");
					}
					if (bean.getRes().getCheck_report_status().equals("3")) {
						tvStatus.setText("商家已拒绝验收报告,请再次编辑");
						btnAgainSubmitReport.setVisibility(View.VISIBLE);
					}
					break;
				case "5":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("验收发票");
					btnConfirmInvoice.setVisibility(View.VISIBLE);
					break;
				case "6":
					btnApplyArbitration.setVisibility(View.VISIBLE);
					tvStatus.setText("付尾款");
					btnThreeMoney.setVisibility(View.VISIBLE);
					break;
				case "7":
					if (bean.getRes().getIs_comment().equals("1")) {
						btnViewEvaluation.setVisibility(View.VISIBLE);
						tvStatus.setText("已结束");
					} else {
						btnEvaluate.setVisibility(View.VISIBLE);
						tvStatus.setText("待评价");
					}
					break;
				default:
					break;
			}
		}
	}

	private void dismissAllBtn() {
		btnCancelOrder.setVisibility(View.GONE);
		btnApplyArbitration.setVisibility(View.GONE);
		btnWaitArbitration.setVisibility(View.GONE);
		btnViewArbitration.setVisibility(View.GONE);
		btnFirstMoney.setVisibility(View.GONE);
		btnSecondMoney.setVisibility(View.GONE);
		btnSubmitReport.setVisibility(View.GONE);
		btnHasSubmittedReport.setVisibility(View.GONE);
		btnAgainSubmitReport.setVisibility(View.GONE);
		btnConfirmInvoice.setVisibility(View.GONE);
		btnThreeMoney.setVisibility(View.GONE);
		btnEvaluate.setVisibility(View.GONE);
		btnViewEvaluation.setVisibility(View.GONE);
	}

	/**
	 * 订单操作
	 */
	private void orderOperate(String action) {
		if (bean == null) {
			return;
		}
		if (buyerOrderOperateModel == null) {
			buyerOrderOperateModel = new BuyerOrderOperateModel(this, new OnNetBackListener<Bean>() {
				@Override
				public void netBack(Bean data) {
					if (data == null) {
						return;
					}
					if (data.getStatus().equals("1")) {
						Toast.makeText(BuyerOrderDetailActivity.this, "操作成功", Toast.LENGTH_SHORT).show();
						getOrderDetail(true);
					} else {
						Toast.makeText(BuyerOrderDetailActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			});
		}
		buyerOrderOperateSubmitBean.setOrderId(beanId);
		buyerOrderOperateSubmitBean.setAction(action);
		buyerOrderOperateModel.request(JSONUtil.toJSON(buyerOrderOperateSubmitBean), true);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
				case ARBITRATE://仲裁
					getOrderDetail(true);
					break;
				case SUBMIT_REPORT://提交验收报告
					getOrderDetail(true);
					break;
				case EVALUATE://评价
					getOrderDetail(true);
					break;
				default:
					break;
			}
		}
	}

	private void showDialog(final Callback callback) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("确定执行此操作吗?");
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				callback.notice(1);
			}
		});
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}
}
